package net.bwie.realtime.jtp.dim.Function;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.flink.api.common.functions.RichMapFunction;

import java.util.*;

public class HbaseDimMapFunction extends RichMapFunction<String, String> {


    private final Map<String, String> dimMap ;

    public HbaseDimMapFunction(HashMap<String, String> dimMap){
        this.dimMap = dimMap;
    }


    @Override
    public String map(String value) throws Exception {

        // 1. 获取原始数据
        JSONObject jsonObject = JSON.parseObject(value);
         String tableName = jsonObject.getString("table_name");
         //2 增加字段-HBASE的表名
        jsonObject.put("hbase_table_name","dim_"+tableName);
        //添加字段--列簇名称
        jsonObject.put("family_name", "info");
        //添加字段--rowKey值对应字段名称
        jsonObject.put("row_key_column", dimMap.get(jsonObject.getString("table_name")));

        return jsonObject.toJSONString();
    }
}
























































